package com.iweb.work;
import com.iweb.work.Student;
public class Test1 {
    public static void main(String[] args){
        Student[] stu=new Student[4];

        Student stu1=new Student();
        stu1.setName("jack");
        stu1.setAge(28);
        stu1.setDire("java");
        stu1.setSex("男");
        System.out.println("姓名"+stu1.getName()+"\t"+"性别"+stu1.getSex()+"\t"+"年龄"+stu1.getAge()+"\t"+"方向"+stu1.getDire());

        Student stu2=new Student();
        stu2.setName("rose");
        stu2.setAge(18);
        stu2.setDire(".net");
        stu2.setSex("男");
        System.out.println("姓名"+stu2.getName()+"\t"+"性别"+stu2.getSex()+"\t"+"年龄"+stu2.getAge()+"\t"+"方向"+stu2.getDire());

        Student stu3=new Student();
        stu3.setName("lobi");
        stu3.setAge(45);
        stu3.setDire("java");
        stu3.setSex("女");
        System.out.println("姓名"+stu3.getName()+"\t"+"性别"+stu3.getSex()+"\t"+"年龄"+stu3.getAge()+"\t"+"方向"+stu3.getDire());

        Student stu4=new Student();
        stu4.setName("curr");
        stu4.setAge(37);
        stu4.setDire(".net");
        stu4.setSex("男");
        System.out.println("姓名"+stu4.getName()+"\t"+"性别"+stu4.getSex()+"\t"+"年龄"+stu4.getAge()+"\t"+"方向"+stu4.getDire());


        stu[0]=stu1;
        stu[1]=stu2;
        stu[2]=stu3;
        stu[3]=stu4;
        //循环数组中的每个对象
        Student temp=stu[0];
        for(int i=0;i<stu.length-1;i++){
            for(int j=0;j<stu.length-1-i;j++){
                if(stu[j].getAge()>stu[j+1].getAge()){
                    temp=stu[j];
                    stu[j]=stu[j+1];
                    stu[j+1]=temp;
                }
            }
        }
        for(int i=0;i<stu.length;i++){
            System.out.println(stu[i].getAge()+"\t"+stu[i].getSex()+"\t"+stu[i].getDire()+"\t"+stu[i].getName());
        }
    }
}
